﻿using System;
using System.Collections;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKRevitKernel.ElementSearchUtility.LinkDocumentSuite;
using YJKPatternSign.StairsRoomSection.DataDefine;
using YJKPatternSign.StairsRoomSection.SignElems;

namespace YJKPatternSign.StairsRoomSection.Manager
{
	public class SignElementCls
	{
		public SignElementCls(ExternalCommandData commandData, prepareElementsCls PrepareObj, SectionViewData viewDataObj)
		{
			this.m_commandData = commandData;
			this.m_secViewData = viewDataObj.clone();
			this.m_doc = this.m_secViewData.SectionView.Document;
			this.m_SignData = new SignElementData(viewDataObj, PrepareObj);
		}

		public bool sign()
		{
			if (!this.m_SignData.InitSignElementData())
			{
				return false;
			}
			Transaction transaction = transaction = new Transaction(this.m_doc, "剖面标注");
			try
			{
				transaction.Start();
				new LevelSign(this.m_secViewData, this.m_SignData.BaseLineLayer, this.m_SignData.LstLevel).Sign();
				new StairsRunSign(this.m_doc, this.m_SignData.LstStairs, this.m_SignData.BaseLineRun, this.m_SignData.DimNormal).Sign();
				List<BaseLinkDocumentResultBean> lstWall = new List<BaseLinkDocumentResultBean>();
				if (this.m_SignData.DicWall.Count > 0)
				{
					object obj = this.m_SignData.DicWall.Values.GetEnumerator();
					((IEnumerator)obj).MoveNext();
					lstWall = ((IEnumerator<List<BaseLinkDocumentResultBean>>)obj).Current;
				}
				new HorizontalSign(this.m_secViewData, this.m_SignData.LstGrid, lstWall).Sign();
				new WindowsSign(this.m_doc, this.m_SignData.LstWindowCut, this.m_SignData.LstWindowSee, this.m_SignData.LstFloorBottomElevator, this.m_secViewData.m_SecLine).Sign();
				new DoorSign(this.m_doc, this.m_SignData.LstDoorCut, this.m_SignData.LstDoorSee, this.m_SignData.LstFloorBottomElevator, this.m_secViewData.m_SecLine).Sign();
				new StairsRailingSign(this.m_doc, this.m_SignData.LstStairsRailing, this.m_SignData.LstStairs).Sign();
				new StairsLandingSign(this.m_commandData, this.m_doc, this.m_SignData.LstStairs, this.m_SignData.DicElevator2LayerName).Sign();
				new FloorSign(this.m_commandData, this.m_SignData.LstFloor, this.m_secViewData, this.m_SignData.DicElevator2LayerName).Sign();
				transaction.Commit();
			}
			catch (Exception)
			{
				if (transaction.IsValidObject && transaction.HasStarted())
				{
					transaction.RollBack();
				}
				return false;
			}
			return true;
		}

		private ExternalCommandData m_commandData;

		private SectionViewData m_secViewData;

		private Document m_doc;

		private SignElementData m_SignData;
	}
}
